Replace Function
Replaces the first occurrence of a String with another String.
Syntax
result = Replace( sourceString, oldString, newString )
result = stringVariable.Replace( oldString, newString )
Parameters | ||
sourceString |
The original string. |
|
oldString |
The characters to be replaced. |
|
newString |
The replacement characters. |
Notes
Replaces the first occurrence of oldString in sourceString with newString. Replace is case-insensitive.
If newString is an empty string (""), the Replace function deletes the first occurrence of the oldString in the sourceString.
If oldString is an empty string (""), the Replace function returns an unchanged copy of the sourceString.
Examples
Below are some examples that show the results of the Replace function:
result=Replace ("The quick fox","fox","rabbit") //returns "The quick rabbit"
result=Replace("The quick fox","f","b") //returns "The quick box"
result=Replace("The quick fox","quick","") //returns "The fox"
Using the second syntax:
s="The quick fox"
result=s.Replace ("fox","rabbit") //returns "The quick rabbit"
MsgBox result
See Also
ReplaceAll, ReplaceAllB, ReplaceB, ReplaceLineEndings functions.